<template>
        <el-aside width="200px;">
            <el-menu class="el-menu-vertical-demo" background-color="#545c64"text-color="#fff" >
                  <el-menu-item
        :index="item.path"
        v-for="item in noChildren()"
        :key="item.path"
        @click="clickMenu(item)"
      >
        <component class="icons" :is="item.icon"></component>
        <span>{{ item.label }}</span>
      </el-menu-item>
      <el-sub-menu
        :index="item.label"
        v-for="item in hasChildren()"
        :key="item.path"
      >
        <template #title>
          <component class="icons" :is="item.icon"></component>
          <span>{{ item.label }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            :index="subItem.path"
            v-for="(subItem, subIndex) in item.children"
            :key="subIndex"
            @click="clickMenu(subItem)"
          >
            <component class="icons" :is="subItem.icon"></component>
            <span>{{ subItem.label }}</span>
          </el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script>
import{useRouter}from 'vue-router'
export default {
      setup() {
            const list = [
                  {
                        path:"/",
                        name:"user",
                        label:"用户端管理",
                        icon:"user",
                        url:"UserManage/UserManage",
                  },
                  {
                        label:"迈迪科产品",
                        icon:"location",
                        path:"/Other",
                        children:[
                             {
                        path:"/page1",
                        name:"page1",
                        label:"产品概况",
                        icon:"setting",
                        url:"Other/PageOne",
                  },
                  {
                        path:"/page2",
                        name:"page2",
                        label:"产品特点",
                        icon:"setting",
                        url:"Other/PageTwo",
                  }, 
                        ]
                  },
                  {
                        label:"购买与维修",
                        icon:"location",
                        path:"/Other2",
                        children:[
                             {
                        path:"/page3",
                        name:"page3",
                        label:"产品购买",
                        icon:"setting",
                        url:"Other/PageThree",
                  },
                  {
                        path:"/page4",
                        name:"page4",
                        label:"维修/售后",
                        icon:"setting",
                        url:"Other/PageFour",
                  }, 
                        ]
                  },
                  
            ];
            const router = useRouter();
            const noChildren=()=>{
                  return list.filter((item)=>!item.children);
            };
            const hasChildren=()=>{
                  return list.filter((item)=>item.children);
            };
            const clickMenu =(item)=>{
                  router.push({
                        name:item.name,
                  })
            }
            return {noChildren,hasChildren,clickMenu}
      },
}
</script>
<style lang='less' scoped>
.icons{
      width:18px;
      height:19px
}
</style>